package com.whosly.rapid.lang.thread.support;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;

/**
 * 基础并发类
 *
 * @Author yueny09 <deep_blue_yang@126.com>
 * @Date 2019-12-02 10:38
 */
public abstract class AbstractConcurrent {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Test
    public void conc(){
        final CountDownLatch latch = new CountDownLatch(countr());

        for(int i = 0; i<countr(); i++){
            new Thread(){
                @Override
                public void run() {
                    super.run();
                    exec();
                    latch.countDown();
                }
            }.start();
        }

        try {
            latch.await();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    abstract int countr();
    abstract void exec();
}
